
Imports std
Imports System.IO

Module main

    Sub Main(ByVal args() As String)
        On Error Resume Next
        Dim reader As TextReader = Nothing
        Dim writer As TextWriter = Nothing
        Dim input As String = Nothing
        Dim i As Int32

        If args.Length() = 0 Then
            raiseError("argument count error, input1 input2 ... inputN, " + _
                        "if input is /-, use console, output will always be the console.", _
                        errorHandle.errorType.critical)
        Else
            Dim sum As Double = 0
            Dim linecount As UInt64 = 0
            For i = 0 To args.Length() - 1
                If args(i) = "/-" Then
                    reader = Console.In
                Else
                    reader = New StreamReader(New FileStream(args(i), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                End If
                assert(Not reader Is Nothing, "file no found " + args(i))

                input = reader.ReadLine
                While Not input Is Nothing
                    sum += Convert.ToDouble(input)
                    linecount += 1
                    input = reader.ReadLine
                End While

                closestream(reader)
            Next

            Console.WriteLine("summary" + character.tab + Convert.ToString(sum))
            Console.WriteLine("linecount" + character.tab + Convert.ToString(linecount))
            Console.WriteLine("average" + character.tab + Convert.ToString(sum / linecount))
        End If
    End Sub

End Module
